'''
个人资料页面类
'''
from time import sleep
from selenium.common import NoSuchElementException
from framwork.pages.base_page import BasePage
# 引入by方法
from selenium.webdriver.common.by import By

class PersonalDataPage(BasePage):
    choose_file_locator = (By.ID, "file_upload")
    email_locator = (By.NAME, "email")
    phone_locator = (By.NAME, "telephone")
    save_btn_locator = (By.CSS_SELECTOR, "input[value='保存']")
    #修改信息成功locator
    edit_seccess_locator = (By.CSS_SELECTOR, "body > div.container > div.row > div:nth-child(1) > div")
    error_tips_locator = (By.CSS_SELECTOR, "#dialog_tips > span")   #错误提示信息
    def choose_file(self, tx_jpg):
        '''上传头像图片'''
        self.find_element(self.choose_file_locator).send_keys(tx_jpg)

    def input_email(self, email):
        '''输入邮箱'''
        self.find_element(self.email_locator).clear()
        sleep(1)
        self.find_element(self.email_locator).send_keys(email)

    def input_phone(self, phone):
        '''输入手机号'''
        self.find_element(self.phone_locator).send_keys(phone)

    def clear_phone(self):
        '''清空手机号字段'''
        self.find_element(self.phone_locator).clear()


    def click_save(self):
        '''点击保存按钮'''
        self.find_element(self.save_btn_locator).click()

    def edit_seccess_text(self):
        '''修改信息成功断言文本'''
        try:
            text = self.find_element(self.edit_seccess_locator).text
        except NoSuchElementException:
            text = ""
        return text

    def error_tips_text(self):
        '''错误提示信息断言文本'''
        try:
            text = self.find_element(self.error_tips_locator).text
        except NoSuchElementException:
            text = ""
        return text